/**
 * 世界坐标转经纬度
 * @param {x,y,z} param0 世界坐标
 * @param viewer 
 * @returns 
 */
export const WorldToLonLat = ({x, y, z}, viewer) => {
  const ellipsoid = viewer.scene.globe.ellipsoid
  const cartesian3 = new Cesium.Cartesian3(x, y, z)
  const cartographic = ellipsoid.cartesianToCartographic(cartesian3)
  const lat = Cesium.Math.toDegrees(cartographic.latitude)
  const lon = Cesium.Math.toDegrees(cartographic.longitude)
  const alt = cartographic.height
  return [
    lon,
    lat,
    alt
  ]
}

/**
 * 经纬度转世界坐标
 * @param {number} lon 经度
 * @param {number} lat 纬度
 * @param {number} height 
 * @returns 
 */
export const LngLatToWorld = (lat:number, lon:number, height:number) => {
  return Cesium.Cartesian3.fromDegrees(lon, lat, height)
}

/**
 * 经纬度转弧度
 * @param {number} lon 经度
 * @param {number} lat 纬度
 * @param {number} height 
 * @returns 
 */
export const LngLatToRadian = (lon:number, lat:number, height:number) => {
  return Cesium.Cartographic.fromDegrees(lon, lat, height)
}

/**
 * 弧度转经纬度
 * @param {number} hulon 
 * @param {number} hulat 
 * @param {number} huheight 
 * @returns 
 */
export const RadianToLngLat = (hulon:number, hulat:number, huheight:number) => {
  const longitude = Cesium.Math.toDegrees(hulon) //将弧度转为度
  const latitude = Cesium.Math.toDegrees(hulat)
  const height = Cesium.Math.toDegrees(huheight)
  return {
    longitude,
    latitude,
    height
  }
}

/**
 * 世界坐标转屏幕坐标 
 * @param {x , y, z} param0 世界坐标
 * @param viewer 
 * @returns 
 */
export const WorldToScreen = ({x, y, z},viewer: any) => {
  return Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, {
    x, y, z
  })
}

/**
 * 屏幕坐标转世界坐标
 * @param left 
 * @param top 
 * @param viewer 
 * @returns 
 */
export const ScreenToWorld = (left:number, top:number, viewer:any) => {
  const pick1 = new Cesium.Cartesian2(left, top)
  return viewer.scene.globe.pick(
    viewer.camera.getPickRay(pick1),
    viewer.scene
  )

}